#include<stdio.h>
#include<at89c51ed2.h>
#include<mcs51reg.h>
#include<malloc.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include "lcd.h"
#include "io.h"
	
	
void lcdputstr(char *val){ //put characters in a string
	int i;
	int x_Counter;
	
	int y;
	int currentAddr;
	y=0;
	currentAddr=lcdDataRead();
	currentAddr&=0x7F;
	printf("current addr value is %x",currentAddr);
	//currentAddr=currentAddr-1;
	
	if(currentAddr<=0x0F){
		y=0;
		
	}
	else if(currentAddr>=0x40&&currentAddr<=0x4F){
		y=1;
		currentAddr=currentAddr-0x40;
	
	}
	else if(currentAddr>=0x10&&currentAddr<=0x1F){
		y=2;
		currentAddr=currentAddr-0x10;
	}
	else if(currentAddr>=0x50&&currentAddr<=0x5F){
		y=3;
		currentAddr=currentAddr-0x50;
	}
	
	//lcdgotoloc(1,15);
	
	x_Counter=16-currentAddr;	



		for(i=0;i<=(strlen(val)-1);i++){
		
			lcdputch(val[i]);
			
			
			x_Counter--;
			printf("X Counter%d\n\r",x_Counter);
			
			if(y==3&&x_Counter==0){
				y=0;
				lcdgotoloc(0,y);
				x_Counter=16;
			}
			
			if(x_Counter==0){
				
				y=y+1;
				lcdgotoloc(0,y);
				x_Counter=16;
			}
			
		}			
		
	
}	
				